#include <math.h>

#include "cpoint.h"

CPoint::CPoint()
{
	this->Set(0.0, 0.0, 0.0);
}

CPoint::CPoint(double dX, double dY, double dZ)
{
	this->Set(dX, dY, dZ);
}

CPoint::CPoint(const CPoint & original)
{
	this->x = original.x;
	this->y = original.y;
	this->z = original.z;
}

void CPoint::Add(CPoint * pP)
{
	this->x += pP->GetX();
	this->y += pP->GetY();
	this->z += pP->GetZ();
}

void CPoint::Add(CPoint P)
{
	this->x += P.GetX();
	this->y += P.GetY();
	this->z += P.GetZ();
}

double CPoint::Distance(CPoint * pP)
{
	double dA = this->GetX()-pP->GetX();
	double dB = this->GetY()-pP->GetY();
	double dC = this->GetZ()-pP->GetZ();

	return sqrt(pow(dA,2)+pow(dB,2)+pow(dC,2));
}

double CPoint::Distance(CPoint P)
{
	double dA = this->GetX()-P.GetX();
	double dB = this->GetY()-P.GetY();
	double dC = this->GetZ()-P.GetZ();

	return sqrt(pow(dA,2)+pow(dB,2)+pow(dC,2));
}

void CPoint::Div(double dVal)
{
	this->Set(this->GetX()/dVal, this->GetY()/dVal, this->GetZ()/dVal);
}

void CPoint::Mult(double dVal)
{
	this->Set(this->GetX()*dVal, this->GetY()*dVal, this->GetZ()*dVal);
}

void CPoint::SetX(double dX)
{
	this->x = dX;
}

void CPoint::SetY(double dY)
{
	this->y = dY;
}

void CPoint::SetZ(double dZ)
{
	this->z = dZ;
}

void CPoint::Set(double dX, double dY, double dZ)
{
	this->SetX(dX);
	this->SetY(dY);
	this->SetZ(dZ);
}

void CPoint::operator =(CPoint original)
{
	this->x = original.GetX();
	this->y = original.GetY();
	this->z = original.GetZ();
}

CPoint CPoint::crossProduct(CPoint P)
{
	return CPoint ((this->GetY()*P.GetZ())-(this->GetZ()*P.GetY()),
				   (this->GetZ()*P.GetX())-(this->GetX()*P.GetZ()),
				   (this->GetX()*P.GetY())-(this->GetY()*P.GetX()));
}

void CPoint::normalize()
{
	double dNorm = sqrt(pow(this->GetX(),2.0) + pow(this->GetY(),2.0) + pow(this->GetZ(),2.0));
	this->Div(dNorm);
}

double CPoint::GetX()
{
	return this->x;
}

double CPoint::GetY()
{
	return this->y;
}

double CPoint::GetZ()
{
	return this->z;
}

bool CPoint::operator ==(const CPoint P)
{
	if (this->x == P.x && this->y == P.y && this->z == P.z)
		return true;
	return false;
}

bool CPoint::operator !=(CPoint P)
{
	return !this->operator ==(P);
}
